package com.yunji.web.product;

import com.yunji.common.annotation.Log;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.enums.common.BusinessType;
import com.yunji.common.utils.ExcelUtil;
import com.yunji.product.business.ProductTypeBusiness;
import com.yunji.product.domain.ProductTypeDO;
import com.yunji.product.params.ProductTypeParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Package com.yunji.web.product
 * FileName:	ProductAgentController.java
 * Copyright:	Copyright © 2024 云集互联 All Rights Reserved
 * Company:		云集互联
 * @version: 1.0
 * @since: JDK 1.8.0_202
 * Create at:   2024-04-01 09:31:06
 * Description:
 * 商品类型交互
 * Modification History:
 * Author					Date						Version			Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-01 09:31:06			1.0				1.0 Version
 */
@Api(tags = "管理端-商品类型")
@RestController
@RequestMapping("/container/type")
public class ProductTypeController extends BaseController {
    @Resource
    ProductTypeBusiness business;

    /**
     * 查询商品类型列表
     */
    @ApiOperation("查询商品类型列表")
//    @PreAuthorize("@ss.hasPermi('container:type:query')")
    @GetMapping("/list")
    public Response<List<ProductTypeDO>> list(@Valid ProductTypeParam param) {
        List<ProductTypeDO> list = business.search(param);
        return ResponseHelper.successWithPage(list);
    }

    /**
     * 导出商品类型列表
     */
    @ApiOperation("导出商品类型列表")
    @Log(title = "商品类型", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('container:type:export')")
    @PostMapping("/export")
    public void export(ProductTypeParam param) {
        List<ProductTypeDO> list = business.search(param);
        ExcelUtil<ProductTypeDO> util = new ExcelUtil<ProductTypeDO>(ProductTypeDO.class);
        util.exportExcel(response, list, "商品类型数据");
    }

    /**
     * 获取商品类型详细信息
     */
    @ApiOperation("获取商品类型详细信息")
    @GetMapping(value = "/{id}")
    public Response<ProductTypeDO> getInfo(@PathVariable("id") Long id) {
        return ResponseHelper.success(business.select(id));
    }

    /**
     * 新增商品类型
     */
    @ApiOperation("新增商品类型")
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('container:type:add')")
    @PostMapping
    public Response<Integer> create(@RequestBody ProductTypeDO productType) {
        return ResponseHelper.success(business.create(productType));
    }

    /**
     * 修改商品类型
     */
    @ApiOperation("修改商品类型")
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('container:type:edit')")
    @PutMapping
    public Response<String> update(@RequestBody ProductTypeDO productType) {
        business.update(productType);
        return ResponseHelper.success("修改成功");
    }

    /**
     * 删除商品类型
     */
    @ApiOperation("删除商品类型")
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('container:type:remove')")
    @DeleteMapping("/{ids}")
    public Response<String> remove(@PathVariable Long[] ids) {
        business.delete(ids);
        return ResponseHelper.success("删除成功");
    }


    @ApiOperation("查看商品类型是否被应用")
    @GetMapping("/inUse/{typeId}")
    public Response<Boolean> inUse(@PathVariable Long typeId) {
        return ResponseHelper.success(business.inUse(typeId));
    }

}
